package labuladong.第二章.反转链表;

import leetcode.Head;
import leetcode.ListNode;

import java.util.List;

/**
 * 递归反转链表
 */
public class Demo01 {
    public static ListNode reverse(ListNode head) {
        if (head.next == null) {
            return head;
        }
        ListNode last = reverse(head.next);
        head.next.next = head;
        head.next = null;
        return last;
    }

    public static void main(String[] args) {
        ListNode head = reverse(Head.genListEven());
        Head.printList(head);
    }
}
